package org.jiajie.coffeecodes.advice;

import org.springframework.aop.BeforeAdvice;
import org.springframework.aop.framework.ProxyFactory;

public class TestAdvice {

    public static void main(String[] args) {
        HelloWorld helloWorld = new HelloWorld();

        // 增强对象
        BeforeAdvice beforeAdvice = new TimeLoggingAop();
        // 组装普通对象和增强对象
        ProxyFactory proxyFactory = new ProxyFactory();
        proxyFactory.setTarget(helloWorld);
        proxyFactory.addAdvice(beforeAdvice);

        // 获取组装后的代理对象
        HelloWorld proxyHellowWorldId = (HelloWorld) proxyFactory.getProxy();
        // 运行
        proxyHellowWorldId.sayHello();
        proxyHellowWorldId.sayHelloWithException();
    }
}
